package meiriyiti

import (
	"fmt"
	"sort"
)

func findKDistantIndices(nums []int, key int, k int) []int {
	ans := make([]int, 0)
	for i, v := range nums {
		if key == v {
			ans = append(ans, i)
		}
	}
	extend := make([]int, 0)
	for _, v := range ans {
		for i := -k; i <= k; i++ {
			d := v + i
			if d >= 0 && d < len(nums) {
				extend = append(extend, d)
			}
		}
	}
	ans = append(ans, extend...)
	sort.Ints(ans)
	// 去重
	res := ans[:1]
	for i := 1; i < len(ans); i++ {
		if ans[i] != ans[i-1] {
			res = append(res, ans[i])
		}
	}
	fmt.Println(res)
	return res
}
